<?php
namespace addons\auxiliary;
use app\common\controller\Addons;
/**
 * 辅助类组件
 * @author colin <colin@tensent.cn>
 */
class Auxiliary extends Addons{
	public $info = array(
		'name'=>'Auxiliary',
		'title'=>'辅助插件',
		'description'=>'在文章中经常使用点赞，评价，收藏等功能',
		'status'=>1,
		'author'=>'Colin',
		'version'=>'0.1'
	);

	/**
	 * 安装
	 * @author colin <colin@tensent.cn>
	 */
	public function install(){
		$this->getisHook('Auxiliary',$this->info['name'],$this->info['description']);		
		$sqldata = file_get_contents(ROOT_PATH.'/Addons/'.$this->info['name'].'/install.sql');
		$sqlFormat = $this->sqlSplit($sqldata, config('database.prefix'));
		$counts = count($sqlFormat);

		for ($i = 0; $i < $counts; $i++) {
			$sql = trim($sqlFormat[$i]);
			db()->execute($sql);
		}
		return true;
	}

	/**
	 * 卸载
	 * @author colin <colin@tensent.cn>
	 */
	public function uninstall(){
		$sqldata = file_get_contents(ROOT_PATH.'/Addons/'.$this->info['name'].'/uninstall.sql');
		$sqlFormat = $this->sqlSplit($sqldata,config('database.prefix'));
		$counts = count($sqlFormat);

		for ($i = 0; $i < $counts; $i++) {
			$sql = trim($sqlFormat[$i]);
			db()->execute($sql);
		}
		return true;
	}

	/**
	 * 获取配置
	 * @author colin <colin@tensent.cn>
	 */
	public function Config(){
		return $this->getConfig();
	}

	/**
	 * 实现的钩子方法
	 * @param param 参数
	 * @author colin <colin@tensent.cn>
	 */
	public function Auxiliary($param){
		//dump(empty($param['type']));die;
		if(!empty($param['type'])){
			$open_auxiliary[] = $param['type'];
		}else{
			/*if($param['type'] == 'collection'){
				$this->assign('from',$param['from']);
			}*/
			$open_auxiliary = explode(',',$this->getConfig()['open_auxiliary']);
		}
		
		$this->assign('config',$open_auxiliary);
		echo $this->fetch('Default/Auxiliary');
	}
}